package org.jugile.web2;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.jugile.util.Jugile;
import org.jugile.util.Props;
import org.jugile.util.Proxy;

public class BaseWorker implements Runnable {
	static Logger log = Logger.getLogger(BaseWorker.class);

	public void run() {
		try {
			while (true) {
				log.info("Worker work started...");
				
				// internal worker request
				Cycle c = new Cycle();
				c.serveSync(null,null); // TODO: implement cleaner way to do this 
//				Object app = Jugile.instantiateObject(Cycle.getPackage() + ".App");
//				Proxy p = new Proxy(app);
//				p.call("worker");
				
				log.info("Worker work done.");
				int secs = Jugile.parseIntSafe(Props.get("jugile.web.workerSleepTime"));
				if (secs == 0) secs = 60;
				Thread.sleep(secs * 1000);
			}
		} catch (InterruptedException e) {
			log.info("Worker stopped");
		}
	}
}

